package cz.cvut.fel.email;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cz.cvut.fel.parser.PartNode;

/**
 * @author Tomba
 *
 * Email Bean used to represent email
 */
public class Email {

	public enum EmailType {
		STRING,
		MULTIPART
	}
	/**
	 * Collection of headers
	 */
	private HashMap<String, String> headers = new HashMap<String, String>(50);

	//private StringBuffer data = new StringBuffer();
	private ArrayList<String> attachments = new ArrayList<String>();
	private ArrayList<String> keys = new ArrayList<String>();
	private String content;
	private InputStream is;
	private EmailType type = EmailType.STRING;
	private PartNode rootNode = null;
	
	static final Logger log = LoggerFactory.getLogger(Email.class);
	
	/**
	 * @return the headers
	 */
	public HashMap<String, String> getHeaders() {
		return headers;
	}

	/**
	 *  Adding header to collection 
	 *  
	 * @param name of header
	 * @param value
	 */
	public void addHeader(String name, String value) {
		headers.put(name.toUpperCase(), value);
	}
	
	/**
	 * @param headers the headers to set
	 */
	public void setHeaders(HashMap<String, String> headers) {
		this.headers = headers;
	}

	
	public void setIs(InputStream is) {
		this.is = is;
	}

	public InputStream getIs() {
		return is;
	}

	public void setRootNode(PartNode rootNode) {
		this.rootNode = rootNode;
	}

	public PartNode getRootNode() {
		return rootNode;
	}

	public void setType(EmailType type) {
		this.type = type;
	}

	public EmailType getType() {
		return type;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Email \n"+rootNode.toString();
	}

	/**
	 * @param attachments the attachments to set
	 */
	public void setAttachments(ArrayList<String> attachments) {
		this.attachments = attachments;
	}
	
	public String getKey(){
		log.warn("Key used using "+this.headers.get("Message-ID"));
		return this.headers.get("Message-ID");
	}

	/**
	 * @return the attachments
	 */
	public ArrayList<String> getAttachments() {
		return attachments;
	}

	/*private void countSHA1() {
		
	}*/

	/**
	 * @param keys the keys to set
	 */
	public void setKeys(ArrayList<String> keys) {
		this.keys = keys;
	}

	/**
	 * @return the keys
	 */
	public ArrayList<String> getKeys() {
		return keys;
	}

	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}
	
}
